<!DOCTYPE html>
<html lang="en">
<head>
  
<meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <!-- <link rel="shortcut icon" href="http://favicon.ico"> -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">


  <link rel="stylesheet" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/sm.min.css">
  <link rel="stylesheet" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/sm-extend.min.css">
  <link rel="stylesheet" type="text/css" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/register.css">
  <script type="text/javascript" src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/common/common/common.js"></script>

  <!-- <link rel="stylesheet" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/sm.min.css">
  <link rel="stylesheet" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/sm-extend.min.css">
  <link rel="stylesheet" type="text/css" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/register.css">
  <script type="text/javascript" src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/common/common/common.js"></script> -->
  <style>

    /*修改标题栏颜色*/
    .bar.bar-nav {
      background-color: #1FCA23;
    }

    /*修改标题栏字体颜色*/
    .bar.bar-nav .title {
      color: #fff;
    }
    
    /*修改工具栏背景颜色*/
    .bar.bar-tab {
      background-color: #FEEA4D;
    }
    #pull-left{
      display:inline-block;
      width: 1.5rem;
      padding-top:0.3rem;
      float: left;
    }
    #pull-left img{
      display: block;
      width: 100%;
    }
    #pull-title{
      display: inline-block;
      /*width: 8.0rem;*/
      height: 2.2rem;
      line-height: 2.2rem;
      float: left;
      /*0.5 header padding; 1.5 a*/
      margin-left: calc(50% - 0.5rem - 1.5rem);
      color: #fff;
      font-size: 16px;
    }
    .schoolclass{
      height:50px;
      padding-left: 15px;
      line-height: 50px;
      border-bottom: 1px solid #DCDCDC;
    }
    /*修改内容区背景色*/
    body{
      background-color:#eeeeee;
    }
    .list-block .item-title.label {
        width: 26%;
    }
    /*验证码倒计时*/
    /*个人*/
    #resetcode{
        border: 1px solid #ccc;
        color: #5f646e;
        text-align: center;
        border-radius: 0.25rem;
        line-height: 1.25rem;
        box-sizing: border-box;
        padding: 0 0.3rem;
        height: 1.35rem;
        position: absolute;
        right:0.3rem;
        top:0.45rem;
        display: none;
    }
    /*学生手机号 验证码*/
    #resetchild{
        border: 1px solid #ccc;
        color: #5f646e;
        text-align: center;
        border-radius: 0.25rem;
        line-height: 1.25rem;
        box-sizing: border-box;
        padding:0 0.2rem;
        height: 1.35rem;
        position: absolute;
        right:0.3rem;
        top:0.45rem;
        display: none;
    }
    #schoolCancel{
      color:#625e5e;
      font-size: 20px;
      width: 50px;
      text-align: center;
    }
    
  </style>
</head>
<body>
  
  <div class="page-group">
    <div class="page">
      <!-- 标题栏 -->
      <header class="bar bar-nav">
         <a href="#" id="pull-left" onclick="backclick()"><img src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/back@2x.png"></a>
         <span id="pull-title">注册</span>
      </header>



        <!-- 点击学校显示出的弹框 -->
         <div id="showschool">
                            <!-- 主题内容部分 必须要放在content 的外部-->
                 <div class="content infinite-scroll infinite-scroll-bottom" data-distance="100" style="background-color: white">
                     <div class="list-block" >
                      <div class="searchbar" style="display: flex;justify-content: space-between;">
                          <!-- <a class="searchbar-cancel" style="color:black;font-size: 14px;">取消</a> -->
                          <div class="search-input" style="width: calc(100% - 45px);">
                            <input type="search" id='search' placeholder='输入学校名称...'>
                          </div>
                          <a id="schoolCancel">返回</a>
                       </div>

                         <ul class="list-container" id="li_block">

                        </ul>
                     </div>
                     <!-- 加载提示符 -->
                     <div class="infinite-scroll-preloader">
                         <div class="preloader"></div>
                     </div>
                 </div>
         </div>


      <!-- 页面内容区域 -->
      <div class="content">
         <div class="identity">
             <span>身份选择</span>
             <a href="#" id="child"><img src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/ced.png"></a>
             <a href="#" id="parents" ><img src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/pno.png"></a>
         </div>
         <!-- 状态信息显示 -->
         <div id="error1"></div>
         <div id="error2"></div>
         <div id="error3"></div>
         <!-- 注册列表 -->
         <!-- <form action="" method="post" id="form1" name="form1"> -->
             <div class="list-block">
                <ul>
                    <li>
                      <div class="item-content">
                        <div class="item-inner" style="position: relative;">
                          <div class="item-title label">手机号</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="regphone">
                          </div>                  
                          <a href="#" class="button button-light" id="getcode" onclick="getcode()">获取验证码</a>
                          <a href="#" id="resetcode"><span id="resettime">60</span><span>s后重新发送</span></a>
                        </div>
                      </div>
                    </li>
                    <li>
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">验证码</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="smscodeid">
                          </div>
                        </div>
                      </div>
                    </li>
                    <li>
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">密码</div>
                          <div class="item-input">
                            <input type="password" placeholder="" id="password">
                          </div>
                         <!--  <span id="error2"></span> -->
                        </div>
                      </div>
                    </li>
                    <li>
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">确认密码</div>
                          <div class="item-input">
                            <input type="password" placeholder="" id="pwd2">
                          </div>
                          <!-- <span id="error3"></span> -->
                        </div>
                      </div>
                    </li>
                </ul>
             </div>
             <div class="list-block">
                <ul>
                    <li id="childphone">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">学生手机号</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="studentphone">
                          </div>
                          <a href="#" class="button button-light" id="childcode" onclick="childcode()">获取验证码</a>
                          <a href="#" id="resetchild"><span id="resettime-child">60</span><span>s后重新发送</span></a>
                        </div>
                      </div>
                    </li>
                    <li id="smscode2" style="display: none;">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">验证码</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="stucodeid">
                          </div>
                        </div>
                      </div>
                    </li>
                    <li>
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label" id="title_name">姓名</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="name">
                          </div>
                        </div>
                      </div>
                    </li>
                    <li id="regemail">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">家长邮箱</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="email"> 
                          </div>
                        </div>
                      </div>
                    </li>
                    <li id="regnumber">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">学号</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="student_no">
                          </div>
                        </div>
                      </div>
                    </li>
                    <li id="regschool">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">学校</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="schoolonly">
                          </div>
                        </div>
                      </div>
                    </li>
                    <li id="reggrade">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">年级</div>
                          <div class="item-input">
                            <input type="text" placeholder="" id="gradeipt">
                          </div>
                        </div>
                      </div>
                    </li>
                    <li id="regclass">
                      <div class="item-content">
                        <div class="item-inner">
                          <div class="item-title label">班级</div>
                          <div class="item-input" id="class_div_input">
                            <input type="text" placeholder="" id="classipt">
                          </div>
                        </div>
                      </div>
                    </li>
                </ul>
<!--                 <div id="showgrade">
                    <h5>请选择你的年级</h5>
                    <ul id="showgrade_list">
                       
                    </ul>
                </div> -->
                
             </div>
             <!-- 注册按钮 -->
             <button id="regbtn" class="themecolor" onclick="register()">注册</button>
         <!-- </form> -->
         
      </div>

    </div>
  </div>

  <!-- !-- 固定的js引用，所有的jQuery 要用 $$ 表示 --> 
<script type="text/javascript" src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/js/js/jquery-1.11.1.min.js"></script>
<!-- 这一行代码是为了 避免js冲突 -->
<script type="text/javascript">var $$ =jQuery.noConflict();</script>

<script type='text/javascript' src='https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/zepto/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/js/js/sm.min.js' charset='utf-8'></script>
<!-- <script type='text/javascript' src='https://gitee.com/huaflower/CommonFile/raw/master/js/sm-extend.min.js' charset='utf-8'></script> -->
<script src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/js/js/swiper/swiper.min.js"></script>
<script type="text/javascript">

      var gradearr = new Array();
      var gradenames = new Array();
      var classnames = new Array();
      var classarr = new Array();


      // 加载flag
      var loading = false;
      var curidentity = 0;//默认身份是学生
      var offset = 0
      var limit = 18

      var lastlength = 18;
      var schoollist = new Array();
      var schoolid = -1;
      var classid = -1;
      var gradeid = -1;

      // 注册'infinite'事件处理函数
      $(document).on('infinite', '.infinite-scroll-bottom',function() {
        console.log(loading);
          // 如果正在加载，则退出
          if (loading) return;

          // 设置flag
          loading = true;

          // 模拟1s的加载过程
          setTimeout(function() {

            console.log("count:"+schoollist.length+"lastlength:"+lastlength+"=====limit"+limit);
              
              console.log('================'+lastlength + '====' + limit);


              if (lastlength < limit) {

                  // 加载完毕，则注销无限加载事件，以防不必要的加载
                  $.detachInfiniteScroll($('.infinite-scroll'));
                  // 删除加载提示符
                  $$('.infinite-scroll-preloader').remove();
                  return;
              }
               offset = schoollist.length;
               schools();
              // 添加新条目
              // addItems(itemsPerLoad, lastIndex);
              // 更新最后加载的序号
              //容器发生改变,如果是js滚动，需要刷新滚动
              $.refreshScroller();
          }, 1000);
      });





   function backclick(){
     native_goto('local/finish');
   }
  
  function clickimg(){
    // 点击学生触发的样式
    $$('#child').click(function(){
          curidentity = 0;
          $$("#title_name").html("姓名");
          // 学生手机号隐藏
          $$('#childphone').hide();
          // 学生手机号验证码显示
          $$('#smscode2').hide();
          // 邮箱隐藏
          $$('#regemail').hide();
          // 学号、学校、年级、班级显示
          $$('#regnumber,#regschool,#reggrade,#regclass').show();
          if($$('#child').find('img').attr('src')=='https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/cno.png'){
              // 学生变为选中状态
              $$('#child').find('img').attr('src','https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/ced.png');
              $$('#child').css({'border':'1px solid #4F94CD'});
              // 家长变为默认状态
              $$('#parents').find('img').attr('src','https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/pno.png');
              $$('#parents').css({'border':'none'});
          }else{
              $$('#child').find('img').attr('src','https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/cno.png');
              $$('#child').css({'border':'none'});
          }
    })
    // 点击家长触发的样式
    $$('#parents').click(function(){

          curidentity = 1;

          $$("#title_name").html("家长姓名");
          // 学生手机号显示
          $$('#childphone').show();
          // 学生手机号验证码显示
          $$('#smscode2').show();
          // 邮箱显示
          $$('#regemail').show();
          // 学号、学校、年级、班级隐藏
          $$('#regnumber,#regschool,#reggrade,#regclass').hide();
          if($$('#parents').find('img').attr('src')=='https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/pno.png'){
              // 家长变为选中状态
              $$('#parents').find('img').attr('src','https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/ped.png');
              $$('#parents').css({'border':'1px solid #4F94CD'});
              // 学生变为默认状态
              $$('#child').find('img').attr('src','https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/cno.png');
              $$('#child').css({'border':'none'});
          }else{
              $$('#parents').find('img').attr('src','https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/pno.png');
              $$('#parents').css({'border':'none'});
          }
    })
    // 点击学校显示出的弹框
    $$('#regschool').click(function(){
         $$('#showschool').show();
    });
    $$('.searchbar-cancel').click(function(){
         $$('#showschool').hide();
    });
    // 点击返回隐藏学校弹出框
    $$('#schoolCancel').click(function(){
         $$('#showschool').hide();
    });
    // 点击年级显示的弹框
    $$('#gradeipt').click(function(){

        $$('#showgrade').show();
    })

    $$('#class_div_input').click(function(){
      

      if(schoolid == -1){//必须要选择学校
        // native_showdialog("请选择您的学校");
        $.toast("请选择您的学校");
        return;
      }
      if(gradeid == -1){//必须要选择学校
        // native_showdialog("请选择您的年级");
        $.toast("请选择您的年级");
        return;
      }

    })



    // 点击年级显示的弹框选择
    $("#gradeipt").picker({
        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-right close-picker">确定</button>\
        <h1 class="title">请选择你的年级</h1>\
        </header>',
        onClose: function(picker,values,displayvalue){
          var curname = $$("#gradeipt").val();
          if(isNotNull(curname)){
            for(var i = 0;i<gradearr.length;i++){
              if(curname == gradearr[i].name){
                  gradeid = gradearr[i].id;
                  break;
              }
            }

            if(schoolid != -1 && gradeid != -1){//必须要选择学校跟年纪
              //获取班级接口
              classes();
            }
          }
          

        },
        cols: [
          {
            textAlign: 'center',
            values: gradenames
          }
        ]
    });

    // 点击班级显示的弹框选择
    $("#classipt").picker({
        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-right close-picker">确定</button>\
        <h1 class="title">请选择你的班级</h1>\
        </header>',
        formatValue:function(picker, value, displayValue){
            return value[0];
        },
        cols: [
          {
            textAlign: 'center',
            values: classnames
          }
        ]
    });
    // 填写信息验证
    // 手机号验证
    $$('#regphone').blur(function(){
        reg =/^1[3|4|5|7|8][0-9]\d{4,8}$/i;
       if( $$(this).val()=="") { 
           $$('#error1').show();
           $$("#error1").html('<span>手机号不能为空！</span>');
           setTimeout('$$("#error1").hide()',2000);

        }
        else if($$(this).val().length<11) {   
          $$('#error1').show();
          $$("#error1").html('<span>手机号输入为11位数字！</span>');
          setTimeout('$$("#error1").hide()',2000);
        }
        else if(!reg.test($$("#regphone").val())) { 
           $$('#error1').show();  
           $$("#error1").html('<span>手机号不存在	！</span>');
           setTimeout('$$("#error1").hide()',2000);

           return false;
        }
        else {
           $$('#error1').hide();
           $$("#error1").html("");
           setTimeout('$$("#error1").hide()',2000);

        }
    })
    // 学生手机号验证
    // $$('#studentphone').blur(function(){
    //     reg =/^1[3|4|5|7|8][0-9]\d{4,8}$/i;
    //    if( $$(this).val()=="") { 
    //        $$('#error1').show();
    //        $$("#error1").html("手机号不能为空！");
    //     }
    //     else if($$(this).val().length<11) {   
    //       $$('#error1').show();
    //       $$("#error1").html("手机号输入为11位数字");
    //     }
    //     else if(!reg.test($$("#regphone").val())) {  
    //        $$('#error1').show(); 
    //        $$("#error1").html("手机号不存在!");
    //        return false;
    //     }
    //     else {
    //        $$('#error1').hide();
    //        $$("#error1").html("");
    //     }
    // })
    // 密码验证
    $$('#password').blur(function(){
        reg=/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$/;
        if(!reg.test($$('#password').val())){
          $$('#error2').show();
          $$("#error2").html('<span>格式有误，请输入6~12位的数字、字母或特殊字符！</span>');
          setTimeout('$$("#error2").hide()',2000);
          return false;
        }
        else 
        { 
          $$('#error2').hide();
          $$("#error2").html('');
          setTimeout('$$("#error2").hide()',2000);
        }
      });
     // 确认密码验证
     $$('#pwd2').blur(function(){
        var pwd1=$$('#password').val();
        var pwd2=$$(this).val();
        if (pwd1!=pwd2) {
          $$('#error3').show();
          $$("#error3").html('<span>两次密码输入不一致！</span>');
          setTimeout('$$("#error3").hide()',2000);
          return false;
        }
        else 
        {
          $$('#error3').hide();
          $$("#error3").html("");
          setTimeout('$$("#error3").hide()',2000);
        }
      });
     // 邮箱验证
      // $$('#email').blur(function(){
      //    var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
      //    if( $$(this).val()=="") { 
      //        $$('#error1').show();
      //        $$("#error1").html("邮箱不能为空！");
      //        return false;
      //     }
      //     else if(!reg.test($$("#email").val())) { 
      //        $$('#error1').show();
      //        $$("#error1").html("邮箱输入错误!");
      //        return false;
      //     }
      //     else {
      //        $$('#error1').hide();
      //        $$("#error1").html("");
      //     }
      // });


  }

  // 点击验证码触发倒计时*个人
  function getcode(){
      getSmsCode();
       
  }
  // 点击验证码触发倒计时*学生手机号
  function childcode(){
    getSmsCodeChild();
  }

   //获取短信验证码*个人
  function getSmsCode(){

    var mobile = $$("#regphone").val();
    if(!isNotNull(mobile)){
        native_showdialog("手机号不能为空！");
        return;
    }

    var param = {
    }
    var url = 'apis/getCode?type=0&mobile='+mobile;
    net_request('get',url,param,codeSuccessCallBack,errorCallBack);
  }

  //获取短信验证码*学生手机号
  function getSmsCodeChild(){

    var mobile = $$("#studentphone").val();
    if(!isNotNull(mobile)){
        native_showdialog("手机号不能为空！");
        return;
    }

    var param = {
    }
    var url = 'apis/getCode2?type=0&mobile='+mobile;
    net_request('get',url,param,codeChildSuccessCallBack,errorCallBack);
  }

//短信验证码回调*个人
function codeSuccessCallBack(data){
  if (isNotNull(data)) {
    var databody = data.data;
    if (isNotNull(databody) && data.success) {
       // 按钮禁用，倒计时60s，60s后按钮可再次点击发送
            $$('#getcode').hide();
            $$("#resetcode").show();
            $$('#resettime').html('60');
            var resettime = 60;
            var timer = null;
            timer = setInterval(function(){
              resettime -= 1;
              if (resettime>0) {
                $$('#resettime').html(resettime);
              }else{
                clearInterval(timer);
                $$('#getcode').show();
                $$('#resetcode').hide();
              }
            },1000);

    }
  }
}

//短信验证码回调*学生手机号
function codeChildSuccessCallBack(data){
  if (isNotNull(data)) {
    var databody = data.data;
    if (isNotNull(databody) && data.success) {
       // 按钮禁用，倒计时60s，60s后按钮可再次点击发送
            $$('#childcode').hide();
            $$('#resetchild').show();
            $$('#resettime-child').html('60');
            var resettime = 60;
            var timer = null;
            timer = setInterval(function(){
              resettime -= 1;
              if (resettime>0) {
                $$('#resettime-child').html(resettime);
              }else{
                clearInterval(timer);
                $$('#childcode').show();
                $$('#resetchild').hide();
              }
            },1000);

    }
  }
}

// 失败返回
function errorCallBack(data){
  console.log(data);
}


//注册接口
function register(){

    var mobile = $$("#regphone").val();
    var password = $$('#password').val();
    var verpassword = $$("#pwd2").val();
    var name = $$('#name').val();
    var smscode = $$("#smscodeid").val();
    var stucode = $$('#stucodeid').val();
    var email = $$('#email').val();
    var student_mobile = $$('#studentphone').val();
    var student_no = "";
    var param = {};

    if(!isNotNull(mobile)){
        native_showdialog("手机号不能为空！");
        return;
    }

    if(!isNotNull(smscode)){
        native_showdialog("验证码不能为空！");
        return;
    }if(!isNotNull(password) || !isNotNull(verpassword)){
        native_showdialog("密码不能为空！");
        return;
    }

    if(password != verpassword ){
        native_showdialog("两次密码输入不一致");
        return;
    }

    if(!isNotNull(name)){
        native_showdialog("姓名不能为空！");
        return;
    }



    if(curidentity == 0){//学生
      student_no = $$('#student_no').val();
      var curname = $$("#gradeipt").val();
      for(var i = 0;i<gradearr.length;i++){
        if(curname == gradearr[i].name){
            gradeid = gradearr[i].id;
            break;
        }
      }

//      if(!isNotNull(student_no)){
 //       native_showdialog("学号不能为空！");
 //       return;
 //     }
  //    if(schoolid == -1){//必须要选择学校
  //      native_showdialog("请选择您的学校");
   //     return;
  //    }
   //   if(gradeid == -1){//必须要选择学校
  //      native_showdialog("请选择您的年级");
  //      return;
    //  }

      // console.log(classarr[0]);
      var curclassname = $$("#classipt").val();
      for(var i = 0;i<classarr.length;i++){
        if(curclassname == classarr[i].name){
            classid = classarr[i].id;
            gradeid = classarr[i].grade_id;
            schoolid = classarr[i].school_id;
            // alert(JSON.stringify(classarr[i]));
            break;
        }
      }

     // if(classid == -1 || !isNotNull(classid)){//必须要选择学校
     //   native_showdialog("请选择您的班级");
   //     return;
   //   }


      param = {
            mobile: mobile,
            smscode:smscode,
            student_no:student_no,
            identity: curidentity,
            school_id:schoolid,
            grade_id:gradeid,
            class_id:classid,
            student_mobile:"",
            name:name,
            email:"",
            password:password
        }
    }else{//家长

    param = {
            mobile: mobile,
            smscode:smscode,
            identity: curidentity,
            student_no:"",
            school_id:"",
            grade_id:"",
            class_id:"",
            student_mobile:student_mobile,
            stucode:"",
            name:name,
            email:email,
            password:password
        }

    }
    var url = 'apis/register';
    net_request('post',url,param,regSuccessCallBack,errorCallBack);
}


function regSuccessCallBack(data){
  if(isNotNull(data)){
    if(data.success){
      native_showtoast("注册成功");
      native_goto("local/finish");
    }else{
      native_showdialog(data.message);
    }
  }

}

 // 输入学校接口
 function schools(){

    var param = {
    }
    var seartext = $$("#search").val();
    var url = 'api/v1/schools?offset='+ offset+'&limit='+limit;
    if(isNotNull(seartext)){
      url = 'api/v1/schools?search=name:'+seartext+'&searchFields=name:like&offset='+offset+'&limit='+limit;
    }else{
      url = 'api/v1/schools?offset='+offset+'&limit='+limit;
    }
    net_request('get',url,param,schoolSuccessCallBack,errorCallBack);
 }
 
 function schoolSuccessCallBack(data){
        if (isNotNull(data)) {
          var databody = data.data;
          if (offset == 0) {
             schoollist = new Array();
          }
            if (isNotNull(databody)) {
                var list = databody.list;
                lastlength = list.length;

                  for (var i = 0; i < list.length; i++) {
                    var item = list[i];
                    schoollist.push(item);
                  }

                  if (isNotNull(schoollist) && schoollist.length > 0) {
                    var html = '';
                    for (var i = 0; i < schoollist.length; i++) {
                          var item = schoollist[i];
         
                          if (isNotNull(item)) {
                            html += '<li sindex="'+i+'" onclick="schoolitemclick(this)" class="schoolclass">'+item.name+'</li>';
                          }           
                    }
                   
                   $$('#li_block').html(html);

                  }else{//数据都为空，清空
                    $$('#li_block').html('');                  
                  }
               
            }
      }
      // 重置加载flag
      loading = false;

      // 加载完毕，则注销无限加载事件，以防不必要的加载
      // $.detachInfiniteScroll($$('.infinite-scroll'));
       
 }

 // 年级接口
 function grades(){
    var param = {}
    var url = 'api/v1/grades';
    net_request('get',url,param,gradeSuccessCallBack,errorCallBack);
 }
 
 function gradeSuccessCallBack(data){
      schools();
       if (isNotNull(data) && data.success) {
         var databody = data.data;
         if (isNotNull(databody) && databody.length > 0) {
          var html = '';
          for (var i = 0; i < databody.length; i++) {
             var item = databody[i];
             if (isNotNull(item)) {
                gradearr.push(item);
                gradenames.push(item.name);
              
             }
            }
          }
      }

      if(schoolid != -1 && gradeid != -1){//必须要选择学校跟年纪
              //获取班级接口
              classes();
      }
 }



 // 班级接口
 function classes(){
  // classarr = new Array();
  // classnames = new Array();
  // classid = "-1";

  var param = {}
  var url = 'api/v1/school_classes?search=grade_id:'+gradeid+';school_id:'+schoolid+'&searchJoin=and';
  net_request('get',url,param,classesSuccessCallBack,errorCallBack);
 }

 function classesSuccessCallBack(data){
  if (isNotNull(data) && data.success) {
         var databody = data.data;
         if (isNotNull(databody) && databody.length > 0) {
          var html = '';
          if(classnames.length != 0){
            classnames = new Array();
          }
          
          classarr = new Array();
          classid = -1;
          for (var i = 0; i < databody.length; i++) {
             var item = databody[i];
             if (isNotNull(item)) {
                classarr.push(item);
                classnames.push(item.name);
              
             }
          }
          // alert(classnames.length);
          $("#classipt").picker("setValue",classnames);
          if(!isNotNull($("#classipt").picker()[0].__eleData.picker.cols[0])){
            $("#classipt").picker("open");
          }
          
          // var piccols = new Array();
          // var piccolsitem = {
          //   textAlign: 'center',
          //   values:classnames
          // };
          // piccols.push(piccolsitem);
          $("#classipt").val("");
          console.log($("#classipt").picker()[0].__eleData.picker);
          if(classnames.length >0){
            $("#classipt").val(classnames[0]);
            $("#classipt").picker()[0].__eleData.picker.value = classnames;
            $("#classipt").picker()[0].__eleData.picker.displayValue = classnames;
          }
          $("#classipt").picker()[0].__eleData.picker.cols[0].values = classnames;

          
          console.log($("#classipt").picker()[0].__eleData.picker.cols);

        }else{
          $.toast("没有查询到班级信息");
          $("#classipt").val("");
          classid = -1;
          classnames = new Array();
          classarr = new Array();
          // console.log($("#classipt").picker()[0].__eleData.picker.cols[0].values.length);
          $("#classipt").picker()[0].__eleData.picker.cols[0].values = classnames;
          // console.log($("#classipt").picker()[0]);

        }
      }

 }

 function initdata(){
  // 点击搜索学校

  $$("#search").bind("input propertychange",function(event){
       
          offset = 0;
          //获取学校数据
          schools();
  });
 }

 function schoolitemclick(cthis){
   var cindex = Number($$(cthis).attr("sindex"));
   schoolid = schoollist[cindex].id;


          var curname = $$("#gradeipt").val();
          if(isNotNull(curname)){
            for(var i = 0;i<gradearr.length;i++){
              if(curname == gradearr[i].name){
                  gradeid = gradearr[i].id;
                  break;
              }
            }


            if(schoolid != -1 && gradeid != -1){//必须要选择学校跟年纪
              //获取班级接口
              classes();
            }
            
            
          }
    
    $$('#showschool').hide();
    $$('#schoolonly').val(schoollist[cindex].name);

 }


  function getParams(data){
   // data需要转成json调用 ，函数urlParamParseJson();
     /*var jodata = JSON.parse(data); 
     if(isNotNull(jodata)){//
        
     }*/

     // if(identity == 0){//学生
        
     // }else{//老师

     // }

  }	
    // 初始化
    $(function(){
      
      clickimg();
      grades();
       
       initdata();


       $.init();
    });
  </script>
</body>
</html>